package count.negative.devau.service;

import java.util.concurrent.ExecutionException;

import android.app.Activity;
import android.app.Application;
import android.os.AsyncTask;
import android.util.Log;

/**
 * 
 * @author count.negative
 * 
 * 
 */

public class RtvService extends ProgramService {
	private final String BASE_URL = "http://m.rtv.de/";

	public RtvService(Application app, Activity activity) {
		super(app, activity);
	}

	@Override
	public String getHTML() {
		if (html == null) {
			AsyncTask task = this.execute(BASE_URL);
			try {
				task.get();
			} catch (InterruptedException e) {
			} catch (ExecutionException e) {
			}
		}

		return html;
	}

	@Override
	public String getHTML(String url) {
		AsyncTask task = this.execute(url);
		try {
			task.get();
		} catch (InterruptedException e) {
		} catch (ExecutionException e) {
		}

		return html;
	}

	/* (non-Javadoc)
	 * @see count.negative.devau.service.ProgramService#getBaseURL()
	 */
	@Override
	public String getBaseURL() {
		return BASE_URL;
	}

	@Override
	protected String convertHTML(String html) {
		long start = System.currentTimeMillis();
		StringBuilder sb = new StringBuilder();

		html = removeTag(html, "<div id=\"siteHeader\"");
		html = removeTag(html, "<div id=\"siteTop\">", "\t\t</div>");
		html = removeTag(html, "<div id=\"siteFooter\"");
		html = removeTag(html, "<div id=\"amobeeAdDiv1\"");
		html = removeTag(html, "<div id=\"amobeeAdDiv2\"");
		html = removeTag(html, "<a href=\"/showComments\" ");
		html = html.replace("<body>", "<body style=\"background-color:#ffffff;\">");
		sb.append(html);
		Log.i("PS", "convertHTML: " + (System.currentTimeMillis() - start));
		return sb.toString();
	}

}
